package cn.school.servlet;

import cn.school.service.SubjectService;
import cn.school.util.StringUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author oldliu
 * @since 1.0
 */
@WebServlet("/delSubjectServlet")
public class DelSubjectServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
//        if(req.getSession().getAttribute("USER_LOGIN")==null){
//            resp.getWriter().print("您还没有登录，不能执行此操作");
//            return;
//        }
        Long id= StringUtil.toLong(req.getParameter("id"));
        int del = SubjectService.INST.del(id);

        if(del>0){
            //out.println("");
            resp.getWriter().print("<script>alert('删除成功');window.location.replace('subjectServlet');</script>");
            return;
        }
        resp.getWriter().print("<script>alert('删除失败!数据可能有关联');window.history.back();</script>");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
